import { createStore, applyMiddleware, combineReducers, compose } from 'redux'
import rootReducer from '../reducers/index'
import { devTools, persistState } from 'redux-devtools';
import thunk from 'redux-thunk';

// const createStoreWithMiddleware = applyMiddleware(
//   thunkMiddleware
// )(createStore)

const finalCreateStore = compose(
  applyMiddleware(thunk),
  devTools(),
  persistState(window.location.href.match(/[?&]debug_session=([^&]+)\b/))
)(createStore);

// const finalCreateStore = compose(
//   applyMiddleware(thunk)
// )(createStore);

export default function configureStore(initialState) {
  //const store = createStoreWithMiddleware(rootReducer, initialState)
 const store = finalCreateStore(rootReducer);

  // if (module.hot) {
  //   // Enable Webpack hot module replacement for reducers
  //   module.hot.accept('../reducers', () => {
  //     const nextRootReducer = require('../reducers')
  //     store.replaceReducer(nextRootReducer)
  //   })
  // }

  return store
}
